package com.example.application.views.study;

import com.example.application.views.main.MainView;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.H1;
import com.vaadin.flow.router.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Route(value = "two",layout = MainView.class)
@PageTitle("页面二")
public class TwoView extends Div implements HasUrlParameter<String> {

    private  Div div;

   public TwoView(){

       H1 h1 = new H1("页面二");

        div = new Div();


       this.add(h1,div);
   }

    /**
     * @OptionalParameter  可选参数  只获得一个
     * @WildcardParameter 通配符参数  他可以获得多个
     * @param beforeEvent
     * @param s
     */
    @Override
    public void setParameter(BeforeEvent  beforeEvent,@WildcardParameter String s) {

       // System.out.println("获得参数="+s);

        //获得查询字符串的方法
     QueryParameters queryParameters =  beforeEvent.getLocation().getQueryParameters();
     Map<String, List<String>> map =queryParameters.getParameters();
     String parms = "";
     Set<String> keys = map.keySet();
        for (String key : keys) {
            parms+="key="+key+" val="+map.get(key)+" ****";
        }
        System.out.println(parms);
        div.setText(parms);
    }
}
